home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 2
/
United Public Domain Gold 2.iso
/
utilities
/
pu625.dms
/
pu625.adf
/
Perfmeter
/
perfmeter.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-03
|
20KB
|
728 lines
;/* PerfMeter by Digital Design, Inc.
lc -j73 -v -y -ba perfmeter.c
blink lib:cback.o+perfmeter.o to perfmeter lib lib:lc.lib+lib:amiga.lib
quit
Author: Juha 'Comm' Tuominen / Digital Design
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Released: 15-Jul-91 v1.10
Revised: 07-Sep-91 v1.11
Revised: 08-Sep-91 v1.12
Revised: 18-Sep-91 v1.2 (needs KS2.0 now)
Revised: 19-Oct-91 v1.21 (uptime bug fixed)
Revised: 04-Nov-91 v2.0 (major bug fixing)
Revised: 25-Nov-92 v2.1 (small bug fix)
Revices: 03-Dec-92 v2.2 (extented font support)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiler: SAS/C v5.10->
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include <exec/tasks.h>
#include <libraries/dos.h>
#include <devices/timer.h>
#include <intuition/intuitionbase.h>
#include <libraries/diskfont.h>
#include <graphics/rastport.h>
#include <graphics/gfx.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <graphics/text.h>
#include <proto/all.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define STACK_SIZE 1000L /* Arska's stack size */
#define NAME "Perfmeter"
#define VERSION 2
#define REVISION 2
#define DATE "02.12.92"
#define VERS "Perfmeter 2.2"
#define VSTRING "PerfMeter 2.2 (03.12.92)\n\0"
#define VERSTAG "\0$VER: Perfmeter 2.2 (03.12.92)\0"
#define FONTSIZE 8
#define FONTNAME "blob.font"
#define WINDOWWIDTH 172
#define WINDOWHEIGTH 130
long _stack=16384;
char *_procname=VSTRING;
long _priority=5;
long _BackGroundIO=FALSE;
void MemCleanup() {}
UBYTE versiontag[]=VERSTAG; /* for version command */
BOOL task_added=FALSE,zipped=FALSE,oldzipped=FALSE,timeropen=FALSE,timeropen2=FALSE,
keepgoing=TRUE,time_requested=FALSE,time_requested2=FALSE;
ULONG maxchip, maxfast, freechip=0, freefast=0,maxpub,freepub,cputime=NULL,
cputemp=NULL,prevcpu=68,count=0,chipscale=0, fastscale=0, publicscale=0,
jakaja=0,cputemp2=0,tag1;
char processor[10]="68000",*taskname="Arska Väijy",itemname[10]=" Idle";
int cpuload=0,mode=0,oldmode=1,buffer[7][151],load=0,switchcount=0,upsecs=0,
upmins=0,uphours=0,updays=0,oldi=0,offset;
UBYTE xc[]={5,5,5,5,5,5,6,6,6,7,7,7,8,8,9,9,10,11,11,12,13,13,14,15,16,17,18,19,20,20,21,23,24,25,26,27,28,29,30,31,33,34,35,36,38,39,40,41,42,44,45,46,48,49,50,51,52,54,55,56,57,59,60,61,62,63,64,65,66,67,69,70,70,71,72,73,74,75,76,77,77,78,79,79,80,81,81,82,82,83,83,83,84,84,84,85,85,85,85,85,85},
yc[]={45,46,48,49,50,51,52,54,55,56,57,59,60,61,62,63,64,65,66,67,69,70,70,71,72,73,74,75,76,77,77,78,79,79,80,81,81,82,82,83,83,83,84,84,84,85,85,85,85,85,85,85,85,85,85,85,84,84,84,83,83,83,82,82,81,81,80,79,79,78,77,77,76,75,74,73,72,71,70,70,69,67,66,65,64,63,62,61,60,59,57,56,55,54,52,51,50,49,48,46,45},
xx[]={15,15,15,15,15,15,15,15,15,16,16,16,16,17,17,17,18,18,18,19,19,20,20,21,21,22,22,23,24,24,25,26,26,27,28,29,29,30,31,32,33,33,34,35,36,37,38,39,40,40,41,42,43,44,45,46,47,48,49,49,50,51,52,53,54,55,56,56,57,58,59,60,60,61,62,63,63,64,65,66,66,67,67,68,69,69,70,70,71,71,72,72,72,73,73,73,74,74,74,74,74,75,75,75,75,75,75,75,75,75},
yy[]={43,44,45,46,47,48,49,49,50,51,52,53,54,55,56,56,57,58,59,60,60,61,62,63,63,64,65,66,66,67,67,68,69,69,70,70,71,71,72,72,72,73,73,73,74,74,74,74,74,75,75,75,75,75,75,75,75,75,75,75,75,74,74,74,74,73,73,73,72,72,72,71,71,70,70,69,69,68,68,67,66,66,65,64,64,63,62,61,61,60,59,58,57,57,56,55,54,53,52,51,50,50,49,48,47,46,45,44,43,43};
APTR stack=NULL;
WORD cordinates[]={0,0,100,65}; /* zipped window cordinates and size */
extern struct ExecBase *SysBase;
struct IntuitionBase *IntuitionBase=NULL;
struct Library *DiskfontBase=NULL;
struct Window *window=NULL;
struct IntuiText abouttext[];
struct IntuiText proceed;
struct GfxBase *GfxBase=NULL;
struct MsgPort *timerport=NULL;
struct timerequest *timermsg=NULL;
struct MsgPort *timerport2=NULL;
struct timerequest *timermsg2=NULL;
struct Task *task=NULL;
struct TextFont *textfont;
struct NewWindow mywindow =
{ 420,
14,
WINDOWWIDTH,
WINDOWHEIGTH,
0,1,
CLOSEWINDOW | MENUPICK | NEWSIZE,
SMART_REFRESH | WINDOWDRAG | WINDOWCLOSE | WINDOWDEPTH,
NULL,
NULL,
"Perfmeter",
NULL,
NULL,
140,
90,
NULL,
NULL,
WBENCHSCREEN
};
struct TagItem tagitems[2]={
{WA_Zoom,&cordinates},
{0,}
};
struct TextAttr TOPAZ80 = {(STRPTR)"topaz.font",TOPAZ_EIGHTY,0,0};
struct IntuiText abouttext[9] =
{
{2,1,JAM1,8, 4,(struct TextAttr *)&TOPAZ80,(UBYTE *)VERS,(struct IntuiText *)&abouttext[1]},
{2,1,JAM1,8,14,(struct TextAttr *)&TOPAZ80,(UBYTE *)"by Juha Tuominen",(struct IntuiText *)&abouttext[2]},
{2,1,JAM1,8,22,(struct TextAttr *)&TOPAZ80,(UBYTE *)"Copyright © 1992",(struct IntuiText *)&abouttext[3]},
{2,1,JAM1,8,30,(struct TextAttr *)&TOPAZ80,(UBYTE *)"Digital Design, Inc.",(struct IntuiText *)&abouttext[4]},
{2,1,JAM1,8,38,(struct TextAttr *)&TOPAZ80,(UBYTE *)" ",(struct IntuiText *)&abouttext[5]},
{2,1,JAM1,8,46,(struct TextAttr *)&TOPAZ80,(UBYTE *)"Average 88100 load: 0 %",(struct IntuiText *)&abouttext[6]},
{2,1,JAM1,8,54,(struct TextAttr *)&TOPAZ80,(UBYTE *)" ",(struct IntuiText *)&abouttext[7]},
{2,1,JAM1,8,62,(struct TextAttr *)&TOPAZ80,(UBYTE *)"Arska Väijy has found",(struct IntuiText *)&abouttext[8]},
{2,1,JAM1,8,70,(struct TextAttr *)&TOPAZ80,(UBYTE *)"0 perfect numbers.",(struct IntuiText *)NULL}
};
struct IntuiText proceed=
{
2,1,JAM1,5,3,(struct TextAttr *)&TOPAZ80,(UBYTE *)"Continue",(struct IntuiText *)NULL
};
/* This menu isn't visually beatufull but do just fine for this program */
struct IntuiText IText1={0,1,JAM1,0,0,&TOPAZ80,"Quit",NULL};
struct MenuItem MenuItem9={NULL,0,64,58,8,ITEMTEXT+ITEMENABLED+HIGHBOX,0,(APTR)&IText1,NULL,NULL,NULL,MENUNULL};
struct IntuiText IText2={0,1,JAM1,0,0,&TOPAZ80,"Switch",NULL};
struct MenuItem MenuItem8={&MenuItem9,0,56,58,8,ITEMTEXT+ITEMENABLED+HIGHCOMP,0,(APTR)&IText2,NULL,NULL,NULL,MENUNULL};
struct IntuiText IText3={0,1,JAM1,0,0,&TOPAZ80,"Public",NULL};
struct MenuItem MenuItem7={&MenuItem8,0,48,58,8,ITEMTEXT+ITEMENABLED+HIGHCOMP,0,(APTR)&IText3,NULL,NULL,NULL,MENUNULL};
struct IntuiText IText4={0,1,JAM1,0,0,&TOPAZ80,"Fast",NULL};
struct MenuItem MenuItem6={&MenuItem7,0,40,58,8,ITEMTEXT+ITEMENABLED+HIGHCOMP,0,(APTR)&IText4,NULL,NULL,NULL,MENUNULL};
struct IntuiText IText5={0,1,JAM1,0,0,&TOPAZ80,"Chip",NULL};
struct MenuItem MenuItem5={&MenuItem6,0,32,58,8,ITEMTEXT+ITEMENABLED+HIGHCOMP,0,(APTR)&IText5,NULL,NULL,NULL,MENUNULL};
struct IntuiText IText6={0,1,JAM1,0,0,&TOPAZ80,"Load",NULL};
struct MenuItem MenuItem4={&MenuItem5,0,24,58,8,ITEMTEXT+ITEMENABLED+HIGHCOMP,0,(APTR)&IText6,NULL,NULL,NULL,MENUNULL};
struct IntuiText IText7={0,1,JAM1,0,0,&TOPAZ80,"CPU",NULL};
struct MenuItem MenuItem3={&MenuItem4,0,16,58,8,ITEMTEXT+ITEMENABLED+HIGHCOMP,0,(APTR)&IText7,NULL,NULL,NULL,MENUNULL};
struct IntuiText IText8={0,1,JAM1,0,0,&TOPAZ80,"Idle",NULL};
struct MenuItem MenuItem2={&MenuItem3,0,8,58,8,ITEMTEXT+ITEMENABLED+HIGHCOMP,0,(APTR)&IText8,NULL,NULL,NULL,MENUNULL};
struct IntuiText IText9={0,1,JAM1,0,0,&TOPAZ80,"About",NULL};
struct MenuItem MenuItem1={&MenuItem2,0,0,58,8,ITEMTEXT+ITEMENABLED+HIGHCOMP,0,(APTR)&IText9,NULL,NULL,NULL,MENUNULL};
struct Menu Menu1={NULL,0,0,62,0, MENUENABLED,"Project",&MenuItem1};
void cleanexit(int error);
void openthings(void);
void addtimerequest(long secs, long micros);
void changefont(void);
void addtimerequest2(long secs, long micros);
void uptime(void);
ULONG maxmemsize(long memtype);
void updatewindow(void);
void oddstuff(void);
void idletask(void);
void __saveds switchroutine(void);
void updatezipped(int i);
void CXBRK(void)
{
cleanexit(0);
}
void cleanexit(int error)
{
if(task_added) RemTask(task);
if(task) FreeMem(task,sizeof(struct Task));
if(stack) FreeMem(stack,STACK_SIZE);
if(timeropen2)
{ if(time_requested2)
{
AbortIO((struct IORequest *)timermsg2);
WaitIO((struct IORequest *)timermsg2);
}
CloseDevice((struct IORequest *)timermsg2);
}
if(timermsg2) DeleteExtIO((struct IORequest *)timermsg2);
if(timerport2) DeletePort(timerport2);
if(timeropen)
{ if(time_requested)
{
AbortIO((struct IORequest *)timermsg);
WaitIO((struct IORequest *)timermsg);
}
CloseDevice((struct IORequest *)timermsg);
}
if(timermsg) DeleteExtIO((struct IORequest *)timermsg);
if(timerport) DeletePort(timerport);
if(window->MenuStrip) ClearMenuStrip(window);
if(window) CloseWindow(window);
if(DiskfontBase) CloseLibrary(DiskfontBase);
if(GfxBase) CloseLibrary((struct Library *)GfxBase);
if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
XCEXIT(error);
}
void openthings(void)
{
int i,j;
if (SysBase->LibNode.lib_Version<36)
cleanexit(99);
if (!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",36L)))
cleanexit(30);
if (!(IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",36L)))
cleanexit(30);
if (!(DiskfontBase=(struct Library*)OpenLibrary("diskfont.library", 36L)))
cleanexit(30);
if(!(timerport=CreatePort(0,0)))
cleanexit(22);
if(!(timermsg=(struct timerequest *) CreateExtIO(timerport, sizeof(struct timerequest))))
cleanexit(22);
if(OpenDevice("timer.device", UNIT_VBLANK, ((struct IORequest *) timermsg), 0))
cleanexit(22);
timeropen=TRUE;
if(!(timerport2=CreatePort(0,0)))
cleanexit(22);
if(!(timermsg2=(struct timerequest *) CreateExtIO(timerport2, sizeof(struct timerequest))))
cleanexit(22);
if(OpenDevice("timer.device", UNIT_VBLANK, ((struct IORequest *) timermsg2), 0))
cleanexit(22);
timeropen2=TRUE;
if(!(window=OpenWindowTagList(&mywindow,(struct TagItem *)&tagitems)))
cleanexit(27);
SetMenuStrip(window,&Menu1);
if(!(stack=AllocMem(STACK_SIZE, MEMF_CLEAR)))
cleanexit(10);
if(!(task=(struct Task*)AllocMem(sizeof(struct Task),MEMF_CLEAR|MEMF_PUBLIC)))
cleanexit(10);
maxchip=maxmemsize(MEMF_CHIP);
maxfast=maxmemsize(MEMF_FAST);
maxpub=maxchip+maxfast;
if(SysBase->AttnFlags & AFF_68010) strcpy(processor,"68010");
if(SysBase->AttnFlags & AFF_68020) strcpy(processor,"68020");
if(SysBase->AttnFlags & AFF_68030) strcpy(processor,"68030");
if(SysBase->AttnFlags & AFF_68040) strcpy(processor,"68040");
/* Because we run this part only once we just have to assume that user
does not add memory cartiges or change the main processor while
this program is running :-)
Yeah really. All non-autoconfigurable boards should be added in the
memory before running Perfmeter. Some strange things might happen
if you don't do so.
*/
chipscale=maxchip/100;
fastscale=maxfast/100;
publicscale=maxpub/100;
if(offset=window->WScreen->BarHeight-8)
SizeWindow(window,0,offset);
/* init buffer */
for(i=0;i<6;i++)
{
for(j=0;j<150;j++)
buffer[i][j]=0;
}
}
void changefont(void)
{
struct TextAttr textattr;
struct TextFont *textfont;
textattr.ta_Name=FONTNAME;;
textattr.ta_YSize=FONTSIZE;
textattr.ta_Style=FS_NORMAL;
textattr.ta_Flags=FPF_ROMFONT | FPF_DISKFONT;
if(textfont=(struct TextFont *)OpenDiskFont(&textattr))
{ SetFont(window->RPort,textfont);
if(!window->RPort->TxHeight==8)
{ cleanexit(10);
}
}
else
{ cleanexit(10);
}
}
void addtimerequest(long secs, long micros)
{
time_requested=TRUE;
timermsg->tr_node.io_Command=TR_ADDREQUEST;
timermsg->tr_time.tv_secs=secs;
timermsg->tr_time.tv_micro=micros;
SendIO((struct IORequest *)timermsg);
}
void addtimerequest2(long secs, long micros)
{
time_requested2=TRUE;
timermsg2->tr_node.io_Command=TR_ADDREQUEST;
timermsg2->tr_time.tv_secs=secs;
timermsg2->tr_time.tv_micro=micros;
SendIO((struct IORequest *)timermsg2);
}
void uptime(void)
{ char temp[30];
if(++upsecs>59)
{ upsecs=0;
if(++upmins>59)
{ upmins=0;
if(++uphours>23)
{ uphours=0;
updays++;
}
}
}
if(!zipped)
{ SetDrMd(window->RPort,JAM2);
SetBPen(window->RPort,0);
SetAPen(window->RPort,1);
Move(window->RPort,10,123+offset);
sprintf(temp,"Uptime: %02d days %02d:%02d:%02d",updays,uphours,upmins,upsecs);
Text(window->RPort,temp,25);
}
}
ULONG maxmemsize(long memtype)
{
ULONG blocksize=0;
struct MemHeader *MemHeader;
Forbid();
for(MemHeader=(struct MemHeader *)SysBase->MemList.lh_Head;MemHeader->mh_Node.ln_Succ;MemHeader=(struct MemHeader *)MemHeader->mh_Node.ln_Succ)
{
if(MemHeader->mh_Attributes&memtype)
blocksize+=((ULONG)MemHeader->mh_Upper-(ULONG)MemHeader->mh_Lower);
}
Permit();
return(blocksize);
/* MaxMemSize() by Louis A. Mamakos. */
}
void updatezipped(int i)
{
UBYTE offset1=0,offset2=0;
char temp[10];
if(oldi<30)
{ offset1=1;
offset2=6;
}
else
{ offset1=3;
offset2=8;
}
SetAPen(window->RPort,0);
Move(window->RPort,53,58+offset);
Draw(window->RPort,6+xx[oldi+offset1],103-yy[oldi+offset1]+offset);
Draw(window->RPort,6+xc[oldi],103-yc[oldi]+offset);
Draw(window->RPort,6+xx[oldi+offset2],103-yy[oldi+offset2]+offset);
Draw(window->RPort,53,58+offset);
Move(window->RPort,14,60+offset);
sprintf(temp,"%d%% ",oldi);
Text(window->RPort,temp,4);
if(i<30) {offset1=1;offset2=6;} else {offset1=3;offset2=8;}
SetAPen(window->RPort,1);
Move(window->RPort,53,58+offset);
Draw(window->RPort,6+xx[i+offset1],103-yy[i+offset1]+offset);
Draw(window->RPort,6+xc[i],103-yc[i]+offset);
Draw(window->RPort,6+xx[i+offset2],103-yy[i+offset2]+offset);
Draw(window->RPort,53,58+offset);
Move(window->RPort,14,60+offset);
sprintf(temp,"%d%% ",i);
Text(window->RPort,temp,4);
for(i=0;i<101;i+=10)
{ Move(window->RPort,3+xc[i],103-yc[i]+offset);
Text(window->RPort,"+",1);
}
Move(window->RPort,56,60+offset);
Text(window->RPort,itemname,6);
}
void updatewindow(void)
{
int i,j;
ULONG curchip, curfast, curpub;
struct RastPort *rp=window->RPort;
char temp[10],temp2[10]; /* two temps for double buffering */
if(mode!=oldmode || oldzipped!=zipped) /* User has decided to look some other item or window zip gadget is pressed*/
{ if(!zipped)
{ sprintf(temp,"%s",itemname);
strcpy(window->Title,temp);
RefreshWindowFrame(window);
SetAPen(rp,0);
RectFill(rp,8,12+offset,164,115+offset);
/* 3D border */
SetAPen(rp,1);
Move(rp,10,111+offset);
Draw(rp,10,16+offset);
Draw(rp,161,16+offset);
SetAPen(rp,2);
Draw(rp,161,111+offset);
Draw(rp,11,111+offset);
/* Scaling lines */
SetAPen(rp,3);
Move(rp,11,38+offset);
Draw(rp,160,38+offset);
Move(rp,11,64+offset);
Draw(rp,160,64+offset);
Move(rp,11,90+offset);
Draw(rp,160,90+offset);
/* Draw existing GFX from buffer */
Move(rp,10,110-buffer[mode][0]+offset);
SetAPen(rp,1);
for(j=1;j<=150;j++)
Draw(rp,j+10,110-buffer[mode][j]+offset);
}
else
{ SetAPen(window->RPort,0);
RectFill(window->RPort,10,15+offset,95,62+offset);
oldi=-1;
strcpy(window->Title,"");
RefreshWindowFrame(window);
}
oldmode=mode;
oldzipped=zipped;
}
/* let's scroll a bit, OK? */
for(i=0;i<7;i++)
{
for(j=0;j<150;j++)
buffer[i][j]=buffer[i][j+1];
}
curchip=AvailMem(MEMF_CHIP);
curfast=AvailMem(MEMF_FAST);
curpub=AvailMem(MEMF_PUBLIC);
buffer[0][150]=(UBYTE)(100*cputemp/60);
buffer[1][150]=load;
buffer[2][150]=(UBYTE)(curchip/chipscale);
if(fastscale)
buffer[3][150]=(UBYTE)(curfast/fastscale);
buffer[4][150]=(UBYTE)(curpub/publicscale);
buffer[5][150]=switchcount;
buffer[6][150]=(UBYTE)(83-(100*cputemp/60));
if(buffer[6][150]<0) buffer[6][150]=0;
for(i=0;i<7;i++)
{ if(buffer[i][150]>93)
{ buffer[i][150]=93;
}
}
if(!zipped)
{ SetDrMd(rp,JAM1);
SetAPen(rp,0);
sprintf(temp,"%d%% ",buffer[mode][149]);
sprintf(temp2,"%d%% ",buffer[mode][150]);
Move(rp,140,24+offset);
Text(rp,temp,4);
ScrollRaster(rp,1,0,11,17+offset,160,110+offset);
SetAPen(rp,1);
Move(rp,140,24+offset);
Text(rp,temp2,4);
SetAPen(rp,3);
WritePixel(rp,160,38+offset);
WritePixel(rp,160,64+offset);
WritePixel(rp,160,90+offset);
SetAPen(rp,1);
Move(rp,159,110-buffer[mode][149]+offset);
Draw(rp,160,110-buffer[mode][150]+offset);
}
else
{ if(oldi!=buffer[mode][150])
{ updatezipped(buffer[mode][150]);
oldi=buffer[mode][150];
}
}
}
void idletask(void) /* This is Arska Väijy */
{
ULONG suurinluku=1,taydellinenluku,luku;
Disable();
task->tc_Switch=switchroutine;
task->tc_Flags|=TF_SWITCH;
Enable();
while(1)
{ taydellinenluku=0;
for(luku=suurinluku;luku>1;luku--)
{
if(!(suurinluku%luku))
taydellinenluku+=luku;
}
if(taydellinenluku==suurinluku)
count++;
suurinluku++;
}
/* As you know, there may not be busy looped parts in multitasking
programs :-) */
}
void __saveds switchroutine(void)
{
/* Thanks to Juhani Vehviläinen for sweatting with me because of
this idle counting routine */
cputime+=SysBase->Quantum-SysBase->Elapsed;
switchcount++;
}
void _main(char *arguments)
{
ULONG timersignal,
timersignal2,
idcmpsignal,
signals,
class;
UWORD code,
qualifier;
struct IntuiMessage *msg=NULL;
char temp1[80],temp2[80];
struct Node *mynode;
ULONG sum1=0;
int pos1=0,pos=0,last[61],length=0,i,j=0,argumentcount=0;
/* handle arguments */
for(i=0;i<strlen(arguments);i++)
{ if(arguments[i]==32 || arguments[i]==13 || arguments[i]==10)
{ if(!strncmp(temp1,"-x",2))
mywindow.LeftEdge=atoi(temp1+2);
if(!strncmp(temp1,"-y",2))
mywindow.TopEdge=atoi(temp1+2);
argumentcount++;
j=0;
}
else
{ temp1[j++]=arguments[i];
temp1[j]=0;
}
}
openthings();
changefont();
for(i=0;i<60;i++)
last[i]=0;
timersignal = 1L << timerport->mp_SigBit;
timersignal2= 1L << timerport2->mp_SigBit;
idcmpsignal = 1L << window->UserPort->mp_SigBit;
addtimerequest(1,0);
addtimerequest2(0,10);
task->tc_Node.ln_Type=NT_TASK;
task->tc_Node.ln_Name=taskname;
task->tc_Node.ln_Pri=-128;
task->tc_SPLower=(APTR)stack;
task->tc_SPUpper=(APTR)(STACK_SIZE+(ULONG)stack);
task->tc_SPReg=task->tc_SPUpper;
AddTask(task,idletask,0L);
task_added=TRUE;
while(keepgoing)
{ signals = Wait(timersignal | timersignal2 | idcmpsignal | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D);
if(signals & (SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D))
cleanexit(0);
if(signals & idcmpsignal)
{
while(msg=(struct IntuiMessage *)GetMsg(window->UserPort))
{
class=msg->Class;
code=msg->Code;
qualifier=msg->Qualifier;
ReplyMsg((struct Message *) msg);
switch(class)
{
case CLOSEWINDOW:
keepgoing=FALSE;
break;
case NEWSIZE:
if(window->Width==WINDOWWIDTH && window->Height==WINDOWHEIGTH+offset)
zipped=FALSE;
else if(!zipped)
{ zipped=TRUE;
if(window->Height<65+offset)
SizeWindow(window,0,offset);
SetAPen(window->RPort,0);
RectFill(window->RPort,10,15+offset,95,62);
}
break;
case MENUPICK:
switch(ITEMNUM(code))
{
case 0:
cputime=100-cpuload;
if(cputime<1 || cputime>100)
cputime=20;
sprintf(temp1,"Average %s load: %d %% ",processor,cputime);
cputime=0;
abouttext[5].IText=(UBYTE *)temp1;
sprintf(temp2,"%d perfect numbers.",count);
abouttext[8].IText=(UBYTE *)temp2;
AutoRequest(NULL,&abouttext[0],NULL,&proceed,NULL,NULL,272,128);
break;
case 1:
mode=0;
strcpy(itemname," Idle");
break;
case 2:
mode=6;
strcpy(itemname," CPU");
break;
case 3:
mode=1;
strcpy(itemname," Load");
break;
case 4:
mode=2;
strcpy(itemname," Chip");
break;
case 5:
mode=3;
strcpy(itemname," Fast");
break;
case 6:
mode=4;
strcpy(itemname,"Public");
break;
case 7:
mode=5;
strcpy(itemname,"Switch");
break;
case 8:
cleanexit(0);
}
break;
}
}
}
if(signals & timersignal)
{
GetMsg(timerport);
addtimerequest(1,0);
uptime();
if(100*cputime/60<100)
cputemp=cputime;
cputemp2+=100*cputime/60;
cputime=0;
cpuload=cputemp2/++jakaja;
length = 0;
Disable();
for(mynode=(SysBase->TaskReady).lh_Head;mynode=mynode->ln_Succ;length++)
;
Enable();
sum1+=(length-last[pos1]);
last[pos]=length;
if(++pos1==60) pos1=0;
if(++pos==60) pos=0;
load=(sum1*100+50)/480;
if(load>100)
load=100;
updatewindow();
switchcount=0;
}
if(signals & timersignal2)
{
GetMsg(timerport2);
addtimerequest2(0,8);
}
}
cleanexit(0);
}